﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PeaceDataCompany.ProjectManager;

namespace ProjectWrapperTestClient.Controllers
{
    public class ProjectsController : Controller
    {
        const string pwaUrl = "http://spbreportportal/PWA/";
        Wrapper wrapper = new Wrapper(pwaUrl);

        //
        // GET: /GetPublishedProjectsPartial/
        public ActionResult GetPublishedProjectsPartial()
        {
            var result = wrapper.GetPublishedProjects();
            return PartialView(result);
        }

        //
        // GET: /GetProjectInfoPartial/
        public ActionResult GetProjectInfoPartial(string name)
        {
            var result = wrapper.GetProject(name,
                x => x.Name,
                x => x.Description,
                x => x.Owner,
                x => x.PercentComplete);
            return PartialView(result);
        }

        //
        // GET: /GetProjectTasksPartial/
        public ActionResult GetProjectTasksPartial(string name)
        {
            var project = wrapper.GetProject(name,
                x => x.Tasks);
            var tasks = project.Tasks;
            return PartialView(tasks);
        }


        //
        // POST: /AddProjectPartial/
        [HttpPost]
        public ActionResult AddProjectPartial(string name, string description, DateTime startDate)
        {
            if (ModelState.IsValid)
            {
                var result = wrapper.CreateProject(name, description, startDate);
                return RedirectToAction("GetPublishedProjectsPartial");
            }
            return View(name, description, startDate);
        }

        //
        // POST: /DeleteProjectPartial/
        [HttpPost]
        public ActionResult DeleteProjectPartial(string name)
        {
            if (ModelState.IsValid)
            {
                var result = wrapper.DeleteTheProject(name);
                return RedirectToAction("GetPublishedProjectsPartial");
            }
            return View(name);
        }

	}
}